Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RDE metadata #1018

Merged
merged 40 commits into from
Nov 28, 2023
Merged

Add RDE metadata #1018

merged 40 commits into from
Nov 28, 2023

Conversation

adambarreiro
Copy link
Collaborator

@adambarreiro adambarreiro commented Mar 14, 2023

Description

This PR adds metadata support to the vcd_rde resource and data source by adding the metadata_entry attribute, which is a set.

The peculiar characteristic about this one is that this is the first OpenAPI metadata feature, so it differs a bit from the existing implementation (XML based). Main differences:

  • There can be multiple metadata entries with same key, but different namespace.
  • Types are reduced in comparison to XML (there's no date, for instance).
  • Each entry has an ID that has to be respected by the Provider during Terraform operations (this is guaranteed by getOpenApiMetadataOperations).

Nuances

As metadata_entry is a set, doing any modification to an entry shows that all entries will be deleted and re-created during terraform plan, which is not true. The code is "smart" enough (getOpenApiMetadataOperations ) to perform the minimal changes, that is, respects the metadata that is not changed and doesn't touch them during terraform apply.

This nuance has been mentioned as a note in the docs. More info:

Sample snippet

provider "vcd" {
# ...  
}


data "vcd_rde_type" "rde_type" {
  vendor  = "vmware"
  nss     = "tkgcluster"
  version = "1.0.0"
}
resource "vcd_rde" "test-rde" {
  org          = "System"
  rde_type_id  = data.vcd_rde_type.rde_type.id
  name         = "TestAccVcdRdeMetadata"
  input_entity = "{\"foo\":\"bar\"}" # We are just testing metadata so we don't care about entity state
  resolve      = true

  metadata_entry {
    key    = "stringKey1"
    value  = "stringValue1"
    type   = "StringEntry"
    domain = "TENANT"

    readonly   = false
    persistent = false
  }
  metadata_entry {
    key    = "numberKey1"
    value  = "1"
    type   = "NumberEntry"
    domain = "TENANT"

    readonly   = false
    persistent = false
  }
  metadata_entry {
    key    = "boolKey1"
    value  = "false"
    type   = "BoolEntry"
    domain = "TENANT"

    readonly   = false
    persistent = false
  }
  metadata_entry {
    key    = "readOnly1"
    value  = "readOnly1"
    type   = "StringEntry"
    domain = "TENANT"

    readonly   = true
    persistent = false
  }
  metadata_entry {
    key        = "namespace"
    value      = "namespace1"
    type       = "StringEntry"
    domain     = "TENANT"
    namespace  = "namespace1"
    readonly   = false
    persistent = false
  }
  metadata_entry {
    key        = "namespace"
    value      = "namespace2"
    type       = "StringEntry"
    domain     = "TENANT"
    namespace  = "namespace2"
    readonly   = false
    persistent = false
  }
  metadata_entry {
    key    = "provider1"
    value  = "provider1"
    type   = "StringEntry"
    domain = "PROVIDER"

    readonly   = false
    persistent = false
  }
  metadata_entry {
    key    = "persistent1"
    value  = "persistent1"
    type   = "StringEntry"
    domain = "TENANT"

    readonly   = false
    persistent = true
  }
}

Remember that RDEs don't have any UI, so these are the endpoints to perform checks in the backend:

# Get RDEs
https://{{vcd_host}}/cloudapi/1.0.0/entities/types/vmware/tkgcluster/1.0.0/

# Get specific RDE with ID metadata (change {{rde_id}} with the RDE urn from previous call, or get it from Terraform state/output)
https://{{vcd_host}}/cloudapi/1.0.0/entities/{{rde_id}}/metadata

To check namespace+key uniqueness, you can add blocks like

metadata_entry {
    key        = "namespace" # Repeat the same key
    value      = "namespace3" # Change the value (otherwise TypeSet considers a duplicate entry and does nothing)
    type       = "StringEntry"
    domain     = "TENANT"
    namespace  = "namespace2" # Repeat the same namespace
    readonly   = false
    persistent = false
}

Signed-off-by: abarreiro <[email protected]>
abarreiro added 7 commits November 20, 2023 12:17
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Fix
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as ready for review November 22, 2023 09:25
@adambarreiro adambarreiro self-assigned this Nov 22, 2023
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as draft November 22, 2023 10:33
abarreiro added 3 commits November 22, 2023 12:12
Fix
Signed-off-by: abarreiro <[email protected]>
Fix
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as ready for review November 22, 2023 11:34
abarreiro added 4 commits November 22, 2023 12:35
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it is in progress yet, but one thing that caught my eye - I left one comment, but this is throughout this PR - we shouldn't test if VCD < 10.4.0 as 3.11 will not support it all anyway. The error user would get error straight from SDK as we require API to be >= 37.0

vcd/metadata_openapi.go Outdated Show resolved Hide resolved
vcd/resource_vcd_rde.go Outdated Show resolved Hide resolved
abarreiro added 3 commits November 22, 2023 12:52
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments from me. I am testing it.

vcd/metadata_openapi.go Outdated Show resolved Hide resolved
vcd/metadata_openapi.go Outdated Show resolved Hide resolved
website/docs/r/rde.html.markdown Outdated Show resolved Hide resolved
abarreiro added 7 commits November 22, 2023 15:37
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
gs
Signed-off-by: abarreiro <[email protected]>
website/docs/r/rde.html.markdown Outdated Show resolved Hide resolved
website/docs/r/rde.html.markdown Outdated Show resolved Hide resolved
website/docs/r/rde.html.markdown Outdated Show resolved Hide resolved
vcd/metadata_openapi_common_test.go Show resolved Hide resolved
abarreiro added 2 commits November 23, 2023 14:34
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
vcd/metadata_openapi.go Outdated Show resolved Hide resolved
vcd/metadata_openapi_common_test.go Show resolved Hide resolved
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as draft November 24, 2023 10:59
abarreiro added 5 commits November 24, 2023 14:51
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro marked this pull request as ready for review November 24, 2023 14:56
Signed-off-by: abarreiro <[email protected]>
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro merged commit ac28799 into vmware:main Nov 28, 2023
3 checks passed
@adambarreiro adambarreiro deleted the add-rde-metadata branch November 28, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants